<template>
  <div class="viewCustomerDetails">
    <div class="header-top">
      <div class="head-title" @click="gotoPage">
        <i class="el-icon-back"></i>自动化规则
      </div>
    </div>
    <div class="content-main">
      <div class="content-title">自动化规则
        <el-switch
            v-model="value"
            active-color="#13ce66">
        </el-switch>
      </div>
      <div class="content-big">
        <div class="content-item">
          <div class="item-left">
            生效企业号：
          </div>
          <div class="item-right">
            <el-button size="small" plain @click="getSelectUser"><i class="el-icon-plus"></i>添加选择</el-button>
            <div class="user-images">
              <span>已选</span>
              <div class="img-li">
                <img src="@/assets/images/profile.jpg"/>
                <img src="@/assets/images/profile.jpg"/>
              </div>
              <div><i class="el-icon-more"></i></div>
              <div class="number">等5个</div>
            </div>
          </div>
        </div>
        <div class="content-item">
          <div class="item-left">
            标签规则：
          </div>
          <div class="item-right">
            <el-table
                :data="tableDataList"
                :max-height="tableHeight"
                ref="companylabelList"
            >
              <el-table-column type="index" width="50"></el-table-column>
              <el-table-column
                  :label="item.label"
                  :align="item.align?item.align:`center`"
                  v-for="(item, index) in tableColumns"
                  :key="index"
                  :prop="item.key"
                  :min-width="item.minWidth ? item.minWidth : ``"
                  :fixed="item.fixed ? item.fixed : false"
                  :show-overflow-tooltip="true"
              >
                <!--用于表格自定义-->
                <template slot-scope="scope">
                  <div class="label-list" v-if="item.key=='label'">
                    <span>未入VIP群</span>
                  </div>
                  <div class="condition" v-else-if="item.key=='condition'">
                    <el-button type="primary" plain @click="handerAddCondition">添加条件</el-button>
                    <div class="labelslectType">所有标签</div>
                    <div class="condition-content">
                      <div class="labelType">所有标签</div>
                      <div class="label-big">
                        <span>孕4周、孕8周、孕12周、孕16周</span>
                      </div>
                      <div class="label-btnBig">
                        <i class="el-icon-delete"></i>
                        <i class="el-icon-edit"></i>
                      </div>
                    </div>
                  </div>
                  <div v-else style="text-align: center">{{ scope.row[item.key] }}</div>
                </template>
              </el-table-column>
              <el-table-column
                  fixed="right"
                  label="操作"
                  width="350">
                <template slot-scope="scope">
                  <div class="operation-big">
                    <!--    添加-->
                    <img src="@/assets/images/icon-add.png"/>
                    <!--    删除-->
                    <img src="@/assets/images/icon-del.png"/>
                    <!--    编辑-->
                    <img src="@/assets/images/icon-edit.png"/>
                    <!--    置顶-->
                    <img src="@/assets/images/icon-di.png"/>
                    <!--    上移-->
                    <img src="@/assets/images/icon-top.png"/>
                    <!--    下移-->
                    <img src="@/assets/images/icon-dwon.png"/>
                    <!--    置底-->
                    <img src="@/assets/images/icon-di.png"/>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </div>
    </div>
    <div class="footer-btn">
      <el-button type="primary">保存配置</el-button>
    </div>
    <chooseCondition v-if="showChooseCondition" :visableIf.sync="showChooseCondition"></chooseCondition>
    <selectByUser v-if="showSelectByUser" :visableIf.sync="showSelectByUser"></selectByUser>
  </div>
</template>

<script>
export default {
  name: 'automationRules',
  components: {
    'chooseCondition': () => import('./chooseCondition.vue'),//导出弹窗
    'selectByUser': () => import('@/views/customerOperationsMgt/circleFriendsMgt/selectByUser.vue'),//导出弹窗
  },
  data() {
    return {
      active: 0,
      showChooseCondition: false,
      showSelectByUser: false,
      value: false,
      form: {
        labelList: [
          {
            name: null,
          }
        ],
      },
      tableHeight: 630,
      tableColumns: [
        {key: 'label', label: `生命阶段`, visible: true, minWidth: 150, fixed: false, align: 'left'},
        {key: 'condition', label: `条件`, visible: true, minWidth: 400, fixed: false, align: 'center'},
      ],
      tableDataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,//用户id
        userName1: null,

      },
      total: 8, // 表格的总条数
      rules: {
        'name': [
          {required: true, message: '请输入标签名称', trigger: 'blur'}
        ],

      },
    }
  },
  created() {
    // this.getList();
    this.tableDataList = [];
    for (let i = 0; i < 10; i++) {
      let obj = {
        name: '小红',
        condition: '初步沟通',
        operate: true,
      }
      this.tableDataList.push(obj);
    }
  },
  mounted() {
  },
  watch: {},
  methods: {
    getSelectUser() {
      //选择企微号
      this.showSelectByUser = true;
    },
    getActive(index) {
      this.active = index;
    },
    handerAddCondition() {
      //添加条件
      this.showChooseCondition = true;
    },
    onSubmit(formName) {
      //提交的代码
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log('提交表单');
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    gotoPage() {
      this.$router.push({
        name: 'customerMgtList',
        query: {
          urlActive: 0,
        }
      })
    },
    handleCloseDialog() {
      this.$emit('update:visableIf', false);
      this.$emit('handleQuery');
    }
  }
}
</script>

<style scoped lang="scss">
.header-top {
  height: 46px;
  background: #fff;
  border-bottom: 1px solid #e9e9e9;
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 20px;

  .head-title {
    font-size: 14px;
    line-height: 22px;
    margin-right: 10px;
    display: flex;
    align-items: center;
    font-weight: bold;

    i {
      font-size: 20px;
      font-weight: bold;
      cursor: pointer;
      margin-right: 10px;
    }
  }

}

.content-main {
  height: calc(100vh - 180px);
  overflow-y: auto;
  background: #fff;
  margin: 12px 12px 76px;
}

.userInfo {
  position: relative;
  background: #fff;
  padding: 16px;
  margin: 12px;
  padding-left: 100px;

  .user-img {
    width: 60px;
    height: 60px;
    position: absolute;
    left: 16px;
    top: 16px;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      border-radius: 4px;

    }
  }

  .user-name {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 0;
    line-height: 24px;
  }

  .user-unit {
    display: inline-block;
    font-size: 12px;
    color: #f90;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .label-list {
    label {
      font-size: 14px;
      line-height: 1.5715;
      word-wrap: break-word;
      font-weight: 400;
    }

    span {
      margin: 4px 4px 4px 0;
      font-size: 12px;
      height: 25px;
      line-height: 25px;
      white-space: nowrap;
      background: #f0f0f0;
      border: 1px solid #e9e9e9;
      border-radius: 4px;
      padding: 0px 7px;
      display: inline-block;

    }
  }
}


.content-title {
  height: 48px;
  border-bottom: 1px solid #e9e9e9;
  display: flex;
  align-items: center;
  padding-left: 20px;

  .el-switch {
    margin-left: 10px;
  }
}

.content-big {
  background: #fff;
  margin: 12px;
  min-height: 600px;
  font-size: 14px;
}

.content-item {
  display: flex;
  margin-right: 10px;
  margin-bottom: 20px;

  .item-left {
    width: 100px;
  }

  .item-right {
    flex: 1;
  }
}

.label-list {
  label {
    font-size: 14px;
    line-height: 1.5715;
    word-wrap: break-word;
    font-weight: 400;
  }

  span {
    margin: 4px 4px 4px 0;
    font-size: 12px;
    height: 25px;
    line-height: 25px;
    white-space: nowrap;
    background: #f0f0f0;
    border: 1px solid #e9e9e9;
    border-radius: 4px;
    padding: 0px 7px;
    display: inline-block;

  }
}

.operation-big {
  display: flex;

  img {
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 10px;
    cursor: pointer;
  }


}

.condition {
  display: flex;
  justify-content: center;
}

.labelslectType {
  height: 30px;
  display: flex;
  align-items: center;
  margin: 0px 10px;
}

.condition-content {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  border: 1px solid #eee;
  padding: 0px 10px;
  margin: 0px 10px;

  .labelType {
    color: #3b74ff;
    margin-right: 10px;
  }

  .label-btnBig {
    font-size: 18px;
    margin-left: 10px;

    i {
      margin: 0px 5px;
    }
  }
}
.user-images {
  height: 50px;
  display: flex;
  align-items: center;
  border: 1px solid #eee;
  padding: 0px 10px;
  color: #888;
  margin-top: 10px;

  .number {
    margin-left: 10px;
  }

  .img-li {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0px 5px;
    overflow: hidden;
    border-radius: 2px;

    img {
      width: 24px;
      height: 24px;
      object-fit: cover;
      margin: 0px 2px;
    }
  }
}
.footer-btn {
  padding: 12px 16px;
  text-align: center;
  background: #fff;
  box-shadow: 0 -4px 4px 0 rgba(0, 0, 0, .05);
  position: fixed;
  left: 226px;
  right: 0;
  bottom: 0;
}
</style>
